﻿@page "/sdk/objects/entity/r/{ParentRecordId}/rl/data/m/{RecordId}"

@model WebVella.Erp.Plugins.SDK.Pages.ErpEntity.DataManageModel
@using WebVella.Erp.Web.Utils;
@{
	Layout = "~/Pages/_AppMaster.cshtml";
	ViewData["Title"] = "Manage entity record";
}

<wv-page-header color="@Model.ErpEntity.Color" area-label="Entities" title="@Model.ErpEntity.Name" subtitle="Record data"
				icon-class="@Model.ErpEntity.IconName" return-url="@Model.ReturnUrl">
	<wv-page-header-actions>
		@foreach (var action in Model.HeaderActions)
		{
			@Html.Raw(action)
		}
	</wv-page-header-actions>

	<wv-page-header-toolbar>
		@foreach (var action in Model.HeaderToolbar)
		{
			@Html.Raw(action)
		}
	</wv-page-header-toolbar>
</wv-page-header>

<wv-validation errors="@Model.Validation.ToErrorList()" message="@Model.Validation.Message"></wv-validation>

<wv-form label-mode="Stacked" mode="Form" name="ManageRecord" validation-errors="Model.Validation.ToErrorList()" id="ManageRecord">
	<wv-section class="mt-4">
		@foreach (var field in Model.Fields)
		{
			var value = Model.Record[field.Name];
			<wv-row>
				<wv-column span="12">
					@if (field.Name == "id" || field.GetFieldType() == FieldType.AutoNumberField)
					{
						<wv-field-text label-text="@field.Label" value="@value" mode="Display"></wv-field-text>
						<input type="hidden" name="@field.Name" value="@value" />
					}
					else
					{
						@switch (field.GetFieldType())
						{
							case FieldType.AutoNumberField:
								{
									<wv-field-autonumber label-text="@field.Label"
														 name="@field.Name"
														 value="@value"
														 mode="Form"
														 label-help-text="@field.HelpText"
														 description="@field.Description"
														 placeholder="@field.PlaceholderText"
														 required="@field.Required"
														 access="@(Model.GetFieldAccess(field))"
														 template="@(((AutoNumberField)field).DisplayFormat)"></wv-field-autonumber>
								}
								break;

							case FieldType.TextField:
								{
									<wv-field-text label-text="@field.Label"
												   name="@field.Name"
												   value="@value"
												   mode="Form"
												   label-help-text="@field.HelpText"
												   description="@field.Description"
												   placeholder="@field.PlaceholderText"
												   required="@field.Required"
												   access="@(Model.GetFieldAccess(field))"
												   maxlength="@(((TextField)field).MaxLength)"></wv-field-text>
                                }
                                break;

                            case FieldType.MultiLineTextField:
                            case FieldType.GeographyField:
                                {
									<wv-field-textarea label-text="@field.Label"
													   name="@field.Name"
													   value="@value"
													   mode="Form"
													   label-help-text="@field.HelpText"
													   description="@field.Description"
													   placeholder="@field.PlaceholderText"
													   required="@field.Required"
													   access="@(Model.GetFieldAccess(field))"></wv-field-textarea>
								}
								break;

							case FieldType.GuidField:
								{
									<wv-field-guid label-text="@field.Label"
												   name="@field.Name"
												   value="@value"
												   mode="Form"
												   label-help-text="@field.HelpText"
												   description="@field.Description"
												   placeholder="@field.PlaceholderText"
												   required="@field.Required"
												   access="@(Model.GetFieldAccess(field))"></wv-field-guid>
								}
								break;

							case FieldType.EmailField:
								{
									<wv-field-email label-text="@field.Label"
													name="@field.Name"
													value="@value"
													mode="Form"
													label-help-text="@field.HelpText"
													description="@field.Description"
													placeholder="@field.PlaceholderText"
													required="@field.Required"
													access="@(Model.GetFieldAccess(field))"
													maxlength="@(((EmailField)field).MaxLength)"></wv-field-email>
								}
								break;

							case FieldType.UrlField:
								{
									<wv-field-url label-text="@field.Label"
												  name="@field.Name"
												  value="@value"
												  mode="Form"
												  label-help-text="@field.HelpText"
												  description="@field.Description"
												  placeholder="@field.PlaceholderText"
												  required="@field.Required"
												  access="@(Model.GetFieldAccess(field))"></wv-field-url>
								}
								break;

							case FieldType.NumberField:
								{
									<wv-field-number label-text="@field.Label"
													 name="@field.Name"
													 value="@value"
													 mode="Form"
													 label-help-text="@field.HelpText"
													 description="@field.Description"
													 placeholder="@field.PlaceholderText"
													 required="@field.Required"
													 access="@(Model.GetFieldAccess(field))"
													 min="@(((NumberField)field).MinValue)"
													 max="@(((NumberField)field).MaxValue)"
													 decimal-digits="@((int?)((NumberField)field).DecimalPlaces ?? 0)"></wv-field-number>
								}
								break;

							case FieldType.CheckboxField:
								{
									<wv-field-checkbox label-text="@field.Label"
													   name="@field.Name"
													   value="@value"
													   mode="Form"
													   label-help-text="@field.HelpText"
													   description="@field.Description"
													   placeholder="@field.PlaceholderText"
													   required="@field.Required"
													   access="@(Model.GetFieldAccess(field))"></wv-field-checkbox>
								}
								break;

							case FieldType.CurrencyField:
								{
									<wv-field-currency label-text="@field.Label"
													   name="@field.Name"
													   value="@value"
													   mode="Form"
													   label-help-text="@field.HelpText"
													   description="@field.Description"
													   placeholder="@field.PlaceholderText"
													   required="@field.Required"
													   access="@(Model.GetFieldAccess(field))"
													   currency-code="@(((CurrencyField)field).Currency.Code)"
													   min="@(((CurrencyField)field).MinValue)"
													   max="@(((CurrencyField)field).MaxValue)"></wv-field-currency>
								}
								break;

							case FieldType.DateField:
								{
									<wv-field-date label-text="@field.Label"
												   name="@field.Name"
												   value="@value"
												   mode="Form"
												   label-help-text="@field.HelpText"
												   description="@field.Description"
												   placeholder="@field.PlaceholderText"
												   required="@field.Required"
												   access="@(Model.GetFieldAccess(field))"></wv-field-date>
								}
								break;

							case FieldType.DateTimeField:
								{
									<wv-field-datetime label-text="@field.Label"
													   name="@field.Name"
													   value="@value"
													   mode="Form"
													   label-help-text="@field.HelpText"
													   description="@field.Description"
													   placeholder="@field.PlaceholderText"
													   required="@field.Required"
													   access="@(Model.GetFieldAccess(field))"></wv-field-datetime>
								}
								break;


							case FieldType.FileField:
								{
									<wv-field-file label-text="@field.Label"
												   name="@field.Name"
												   value="@value"
												   mode="Form"
												   label-help-text="@field.HelpText"
												   description="@field.Description"
												   placeholder="@field.PlaceholderText"
												   required="@field.Required"
												   access="@(Model.GetFieldAccess(field))"></wv-field-file>
								}
								break;

							case FieldType.ImageField:
								{
									<wv-field-image label-text="@field.Label"
													name="@field.Name"
													value="@value"
													mode="Form"
													label-help-text="@field.HelpText"
													description="@field.Description"
													placeholder="@field.PlaceholderText"
													required="@field.Required"
													access="@(Model.GetFieldAccess(field))"></wv-field-image>
								}
								break;

							case FieldType.HtmlField:
								{
									<pre><wv-field-html label-text="@field.Label"
														name="@field.Name"
														value="@value"
														mode="Form"
														label-help-text="@field.HelpText"
														description="@field.Description"
														placeholder="@field.PlaceholderText"
														required="@field.Required"
														access="@(Model.GetFieldAccess(field))"></wv-field-html></pre>
								}
								break;

							case FieldType.PasswordField:
								{
									<wv-field-password label-text="@field.Label"
													   name="@field.Name"
													   value="@value"
													   mode="Form"
													   label-help-text="@field.HelpText"
													   description="@field.Description"
													   placeholder="@field.PlaceholderText"
													   required="@field.Required"
													   access="@(Model.GetFieldAccess(field))"
													   min="@(((PasswordField)field).MinLength)"
													   max="@(((PasswordField)field).MaxLength)"></wv-field-password>
								}
								break;

							case FieldType.PercentField:
								{
									<wv-field-percent label-text="@field.Label"
													  name="@field.Name"
													  value="@value"
													  mode="Form"
													  label-help-text="@field.HelpText"
													  description="@field.Description"
													  placeholder="@field.PlaceholderText"
													  required="@field.Required"
													  access="@(Model.GetFieldAccess(field))"
													  min="@(((PercentField)field).MinValue)"
													  max="@(((PercentField)field).MaxValue)"
													  decimal-digits="@((int?)((PercentField)field).DecimalPlaces ?? 0)"></wv-field-percent>
								}
								break;

							case FieldType.PhoneField:
								{
									<wv-field-phone label-text="@field.Label"
													name="@field.Name"
													value="@value"
													mode="Form"
													label-help-text="@field.HelpText"
													description="@field.Description"
													placeholder="@field.PlaceholderText"
													required="@field.Required"
													access="@(Model.GetFieldAccess(field))"
													maxlength="@(((PhoneField)field).MaxLength)"></wv-field-phone>
								}
								break;

							case FieldType.SelectField:
								{
									<wv-field-select label-text="@field.Label"
													 name="@field.Name"
													 value="@value"
													 mode="Form"
													 label-help-text="@field.HelpText"
													 description="@field.Description"
													 placeholder="@field.PlaceholderText"
													 required="@field.Required"
													 access="@(Model.GetFieldAccess(field))"
													 default-value="@(((SelectField)field).DefaultValue)"
													 options="@(((SelectField)field).Options).ToWvSelectOption()"></wv-field-select>
								}
								break;

							case FieldType.MultiSelectField:
								{
									<wv-field-multiselect label-text="@field.Label"
														  name="@field.Name"
														  value="@value"
														  mode="Form"
														  label-help-text="@field.HelpText"
														  description="@field.Description"
														  placeholder="@field.PlaceholderText"
														  required="@field.Required"
														  access="@(Model.GetFieldAccess(field))"
														  default-value="@(((MultiSelectField)field).DefaultValue)"
														  options="@(((MultiSelectField)field).Options).ToWvSelectOption()"></wv-field-multiselect>
								}
								break;

						}
					}
				</wv-column>
			</wv-row>
		}
	</wv-section>
</wv-form>